package cn.cxq.learning.e1_2;

import java.text.DecimalFormat;

public class HarmonicSeriesSumUtil {

    public static void operation(long value) {

//        System.out.printf("%.15f\n",fromLeftToRight(value));
//        System.out.printf("%.15f\n",fromRightToLeft(value));

        System.out.print(String.format("%.15f ", fromLeftToRight(value)));
        System.out.println(String.format("%.15f", fromRightToLeft(value)));
    }

    private static double fromRightToLeft(long value) {
        double result = 0;
        for (long i = value; i >= 1; i--) {
            result += 1.0 / i;
        }
        return result;
    }

    private static double fromLeftToRight(long value) {

        double result = 0;
        for (long i = 1; i <= value; i++) {
            result += 1.0 / i;
        }
        return result;
    }
}
